package com.hxf.web.action;

import java.io.File;
import java.io.IOException;

import org.apache.struts2.convention.annotation.Result;  
import org.apache.struts2.convention.annotation.Results;

/**
 * 图片上传
 * @author tengyicheng
 *
 */
@Results({@Result(name = "image", location = "upload/image-upload.jsp"),@Result(name = "image2", location = "upload/image-upload2.jsp")})
public class ImagesAction extends ImagesActionBase {  
	private static final long serialVersionUID = 1L;
	
	private int width;
	private int height;
	private File upload; 
	private String uploadFileName;
	private File upload2;
	private String upload2FileName;
	private File upload3;
	private String upload3FileName;
	
	private String imagePath;
	private String imagePath2;
	private String imagePath3;
	
	public String upload() {
		try {
			if (null != uploadFileName && !"".equals(uploadFileName)) {
				imagePath = super.uploadFile(upload, uploadFileName, width, height);
				super.uploadAppFile(upload, uploadFileName, width, height);
				System.out.println(imagePath + "================================");
				getSession().setAttribute("imagePath", imagePath);
			} else {
				getSession().setAttribute("imagePath", null);
			}
			
			if (null != upload2FileName && !"".equals(upload2FileName)) {
				imagePath2 = super.uploadFile(upload2, upload2FileName, width, height);
				getSession().setAttribute("imagePath2", imagePath2);
			} else {
				getSession().setAttribute("imagePath2", null);
			}
			
			if (null != upload3FileName && !"".equals(upload3FileName)) {
				imagePath3 = super.uploadFile(upload3, upload3FileName, width, height);
				getSession().setAttribute("imagePath3", imagePath3);
			} else {
				getSession().setAttribute("imagePath3", null);
			}
			println("0");
		} catch (IOException e) {
			e.printStackTrace();
			logger.debug("upload:" + e.getMessage(), e);
		}
		
		return null;
	}
	
	public String imageUpload() {
		return "image";
	}
	
	public String imageUpload2() {
		return "image2";
	}

	public File getUpload() {
		return upload;
	}

	public void setUpload(File upload) {
		this.upload = upload;
	}

	public String getUploadFileName() {
		return uploadFileName;
	}

	public void setUploadFileName(String uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	public String getImagePath() {
		return imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}

	public File getUpload2() {
		return upload2;
	}

	public void setUpload2(File upload2) {
		this.upload2 = upload2;
	}

	public String getUpload2FileName() {
		return upload2FileName;
	}

	public void setUpload2FileName(String upload2FileName) {
		this.upload2FileName = upload2FileName;
	}

	public File getUpload3() {
		return upload3;
	}

	public void setUpload3(File upload3) {
		this.upload3 = upload3;
	}

	public String getUpload3FileName() {
		return upload3FileName;
	}

	public void setUpload3FileName(String upload3FileName) {
		this.upload3FileName = upload3FileName;
	}

	public String getImagePath2() {
		return imagePath2;
	}

	public void setImagePath2(String imagePath2) {
		this.imagePath2 = imagePath2;
	}

	public String getImagePath3() {
		return imagePath3;
	}

	public void setImagePath3(String imagePath3) {
		this.imagePath3 = imagePath3;
	}
}
